#include <vector>
#include <climits>
using namespace std;

//Dp刷题
class Solution {
public:

//01 矩阵
    vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {
        size_t m = mat.size();
        size_t n = mat[0].size();
        vector<vector<int>> matrix(m, vector<int>(n, INT_MAX>>1));
        for (size_t i=0; i<m; ++i)
        {
            for (size_t j=0; j<n; ++j)
            {
                if (mat[i][j] == 0)
                {
                    matrix[i][j] = 0;
                }
            }
        }

        for (size_t i=0; i<m; ++i)
        {
            for (size_t j=0; j<n; ++j)
            {
                if (i >= 1)
                {
                    matrix[i][j] = min(matrix[i][j], matrix[i-1][j] + 1);
                }
                if (j >= 1)
                {
                    matrix[i][j] = min(matrix[i][j], matrix[i][j-1] + 1);
                }
            }
        }

        for (int i=m-1; i>=0; --i)
        {
            for (int j=n-1; j>=0; --j)
            {
                if (i < m-1)
                {
                    matrix[i][j] = min(matrix[i][j], matrix[i+1][j] + 1);
                }
                if (j < n-1)
                {
                    matrix[i][j] = min(matrix[i][j], matrix[i][j+1] + 1);
                }
            }
        }
        return matrix;
    }
};

//01背包
#include <climits>
#include <iostream>
#include <algorithm>
#include <array>
#include <climits>
using namespace std;

const int N = 1010;

int main()
{

    size_t n = 0;//物品数量
    int v = 0;//背包体积
    cin >> n >> v;

    array<int, N> maxWorth;//物品最大价值
    array<int, N> fillWorth;//背包满时最大价值
    array<int, N> volume;//物品体积
    array<int, N> worth;//物品价值

    fillWorth.fill(INT_MIN);
    fillWorth[0] = 0;

    for (int i = 1; i<=n; ++i)
    {
        cin >> volume[i] >> worth[i];
    }

    for (int i = 1; i<=n; ++i)
    {
        for (int j = v; j>=volume[i]; --j)
        {   
            maxWorth[j] = max(maxWorth[j], maxWorth[j-volume[i]] + worth[i] );
        }
    }

    for (int i = 1; i<=n; ++i)
    {
        for (int j = v; j>=volume[i]; --j)
        {
            if (fillWorth[j - volume[i]] >= 0)
                fillWorth[j] = max(fillWorth[j], fillWorth[j-volume[i]] + worth[i] );
        }
    }

    cout << maxWorth[v] << endl;

    if (fillWorth[v] > 0)
        cout << fillWorth[v] << endl;
    else  
        cout << "0" << endl;

    return 0;
}